package work;

import java.util.ArrayList;
import java.util.List;

// 动物园类
public class Zoo {
    private List<Animal> animals;

    public Zoo() {
        animals = new ArrayList<>();
    }

    public void addAnimal(Animal animal) {
        animals.add(animal);
        System.out.println(animal.getClass().getSimpleName() + "已添加到动物园。");
    }

    public void removeAnimal(Animal animal) {
        animals.remove(animal);
        System.out.println(animal.getClass().getSimpleName() + "已从动物园移除。");
    }

    public void updateAnimal(Animal oldAnimal, Animal newAnimal) {
        removeAnimal(oldAnimal);
        addAnimal(newAnimal);
        System.out.println(newAnimal.getClass().getSimpleName() + "信息已更新。");
    }

    public Animal findAnimalByName(String name) {
        for (Animal animal : animals) {
            if (animal.getClass().getSimpleName().equalsIgnoreCase(name)) {
                return animal;
            }
        }
        return null;
    }

    public void displayAnimals() {
        for (Animal animal : animals) {
            animal.displayDetails();
            System.out.println("-----------------------------------");
        }
    }
}